package org.example.message.controller;

import org.example.message.model.MessageInfo;
import org.example.message.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-06-20
 * Time: 11:12
 */
@RequestMapping("/message")
@RestController
public class MessageController {

    @Autowired
    private MessageService messageService;

    @RequestMapping("/pulish")
    public Boolean pulishMessage(MessageInfo messageInfo){
        if (!StringUtils.hasLength(messageInfo.getFrom())
                ||!StringUtils.hasLength(messageInfo.getMessage())
                ||!StringUtils.hasLength(messageInfo.getTo())){
            return false;
        }
        messageService.addMessage(messageInfo);
        return true;
    }
    @RequestMapping("/get")
    public List<MessageInfo> getMessageInfos(){
        return messageService.getMessage();
    }
}
